package com.fy.controller;

import com.fy.dao.UserMapper;
import com.fy.entity.User;
import com.fy.service.RoundService;
import com.fy.utils.CookieUtils;
import com.fy.utils.JwtUtils;
import com.fy.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;

@RequestMapping("/round")
@Controller
public class RoundController {

    @Autowired
    private RoundService roundService;
    @Autowired
    private UserMapper userMapper;

    private User getUser(HttpServletRequest request){
        String token = request.getHeader("token");
        String account = JwtUtils.getAccount(token);
        User user = new User();
        user.setName(account);
        User singleUser = userMapper.selectOne(user);
        return singleUser;
    }

    @RequestMapping("/publish")
    @ResponseBody
    public String publish(Long productId, String deposit, String startPrice, String stepPrice, String duration, Date startTime, HttpServletRequest request){
        //--获取当前用户
//        User user = UserUtils.getCurrUserFromHeader("token", User.class, request);
        User user = getUser(request);
        Long userId = user.getId();
        return roundService.publish(userId,productId,deposit,startPrice,stepPrice,duration,startTime);
    }
}
